package com.itheima.health.jobs;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.service.OrderService;
import com.itheima.health.vo.OrderStatus;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author MR
 * @title: ClearOverTimeOrderJob
 * @projectName itcast_health
 * @description: TODO
 * @date 2020/8/2614:59
 */
@Slf4j
public class ClearOverTimeOrderJob {
    /*@Autowired
    private JedisPool jedisPool;*/

    @Reference
    private OrderService orderService;

    private static final String NON_PAYMENT = "未支付";
    private static final String HAVE_PAYMENT = "已支付";
    private static final String CANCEL = "取消";

    public void clearOverTimeOrder() throws Exception {
        log.info("[清理过期表]开始...");
        /*try(Jedis jedis = jedisPool.getResource()){
            String keyword = orderService.
        }*/
        //订单过期时间间隔定义（毫秒），这里设置15分钟
        long expireTime = TimeUnit.MINUTES.toMillis(15);
        //获得数据库查询的时间毫秒
        Long expire = System.currentTimeMillis() - expireTime;
        /*Date date = new Date(expire);*/
        System.out.println(expire + ClearOverTimeOrderJob.NON_PAYMENT);
        //查询超时订单表
        List<OrderStatus> list = orderService.selectOverTimeOrder(expire, ClearOverTimeOrderJob.NON_PAYMENT);
        if (list != null) {
            for (OrderStatus orderStatus : list) {
                orderStatus.setOrderStatus(ClearOverTimeOrderJob.CANCEL);
            }
            //修改超时订单状态
            orderService.updateOverTimeOrder(list);
        }
    }
}